#ifndef DATAFILE_H
#define DATAFILE_H
//
#include <QFile>
#include <QDataStream>
#include <qwt_data.h>
#include "cpointerpeakdata.h"
//

class DataFile : public QFile
{
Q_OBJECT
private:
	QFile peakFile;
public:
	int getBlockSize() { openPeakFile(); return blockSize; }
	qint64 samplesCount();
	void setByteOrder(QDataStream::ByteOrder value) { byteOrder = value; }
	QDataStream::ByteOrder getByteOrder() { return byteOrder; }
	qint64 readSamples(QwtCPointerData *& data, qint64 start, qint64 size, int channel);
	qint64 readPeaks( CPointerPeakData *& buff, qint64 start, qint64 count, int channel, float zoom );
	enum DataTypes 
	{
		uint8_t,
		int8_t,
		uint16_t,
		int16_t,
		uint32_t,
		int32_t,
		float_t,
		double_t
	};
	void setDataType(DataTypes value);
	DataTypes getDataType() { return dataType; }
	void setSampleRate( double value) { sampleRate = value; }
	double getSampleRate() { return sampleRate; }
	void setChannels(int value) { channels = value; }
	int getChannels() { return channels; }
	DataFile( const QString & name );
	DataFile( QObject * parent );
	DataFile( const QString & name, QObject * parent );
	virtual ~DataFile();
	int generatePeakFile();
protected:
	bool validatePeakFile();
	bool openPeakFile();
	template <class T> qint64 _readSamples( QwtCPointerData *& data, qint64 start, qint64 maxSamples, int channel );
	template <class T> qint64 _readPeaks( CPointerPeakData *& buff, qint64 start, qint64 count, int channel, int level );
	DataTypes dataType;
	int channels;
	double sampleRate;
	int dataTypeSize;
	QDataStream::ByteOrder byteOrder;
	int blockSize;
	int levels;
};
#endif
